package com.integral.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.druid.util.StringUtils;
import com.integral.biz.IBankExchangeRateBiz;
import com.integral.entity.Bank;
import com.integral.entity.BankExchangeRate;
import com.integral.entity.UserType;
import com.integral.service.BankExchangeRateService;
import com.integral.service.BankService;
import com.integral.service.UserTypeService;
import com.integral.vo.BankExchangeRateVo;

/**
 * @Description: 银行汇率表BIZ实现类
 * @author zhaofan
 * @date 2018年05月08日 上午01:21:46
 */
@Service("bankExchangeRateBiz")
public class BankExchangeRateBiz implements IBankExchangeRateBiz {
	
	/**
	 * 注入银行汇率表Service
	 */
	@Resource
	private BankExchangeRateService bankExchangeRateService;
	@Resource
	private BankService bankService;
	@Resource
	private UserTypeService userTypeService;
	
	/**
	 * @Description: 新增银行汇率表
	 * @param bankExchangeRate
	 * @return 受影响行数
	 * @author zhaofan
	 * @date 2018年05月08日 上午01:21:46
	 */
	public int addBankExchangeRate(BankExchangeRate bankExchangeRate) {
		return bankExchangeRateService.addBankExchangeRate(bankExchangeRate);
	}
	
	/**
	 * @Description: 修改银行汇率表
	 * @param bankExchangeRate 银行汇率表
	 * @return 受影响行数
	 * @author zhaofan
	 * @date 2018年05月08日 上午01:21:46
	 */
	public int updateBankExchangeRate(BankExchangeRate bankExchangeRate) {
		return bankExchangeRateService.updateById(bankExchangeRate);
	}
	
	/**
	 * @Description: 删除银行汇率表
	 * @param id 主键
	 * @return 受影响行数
	 * @author zhaofan
	 * @date 2018年05月08日 上午01:21:46
	 */
	public int deleteBankExchangeRate(Long id) {
		return bankExchangeRateService.deleteById(id);
	}
	
	/**
	 * @Description: 根据ID查询银行汇率表
	 * @param id 主键
	 * @return 银行汇率表
	 * @author zhaofan
	 * @date 2018年05月08日 上午01:21:46
	 */
	public BankExchangeRate findByBankExchangeRate(BankExchangeRateVo bankExchangeRateVo) {
		return bankExchangeRateService.findByBankExchangeRate(bankExchangeRateVo);
	}

	/**
	 * 查询银行汇率信息总记录数
	 * @param bankExchangeRateVo
	 * @return
	 */
	public Long findBankExchangeRateCount(BankExchangeRateVo bankExchangeRateVo){
		return bankExchangeRateService.findBankExchangeRateCount( bankExchangeRateVo);
	}
	
	/**
	 * 查询银行汇率信息
	 * @param bankExchangeRateVo
	 * @return
	 */
	public List<BankExchangeRateVo> findBankExchangeRate(BankExchangeRateVo bankExchangeRateVo){
		List<BankExchangeRateVo> list = bankExchangeRateService.findBankExchangeRate( bankExchangeRateVo);
		for (BankExchangeRateVo bankExchangeRateVo2 : list) {
			//编码转换
			codeTransform(bankExchangeRateVo2);
		}
		return list;
	}
	/**
	 * 编码转换
	 * @param bankExchangeRateVo
	 */
	private void codeTransform(BankExchangeRateVo bankExchangeRateVo){
		//银行信息编码转换
		if(!StringUtils.isEmpty(bankExchangeRateVo.getBankCode())){
			Bank bank = bankService.findByBankCode(bankExchangeRateVo.getBankCode());
			if(null != bank){
				bankExchangeRateVo.setBankName(bank.getBankName());
			}
		}
		//用户类别转换
		if(!StringUtils.isEmpty(bankExchangeRateVo.getUserTypeCode())){
			UserType userType = userTypeService.findByCode(bankExchangeRateVo.getUserTypeCode());
			if(null != userType){
				bankExchangeRateVo.setUserTypeName(userType.getUserTypeName());
			}
		}
	}
}